package com.ncloud.resman.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ncloud.resman.entity.CpeModel;

@Mapper
public interface CpeExtMapper {

	@Select("select model_id,cpu_model,cpu_core_num,ram_model,ram_volume,disk_model,disk_volume,ethernet_num from res_base_cpe_ext"
			+ " where model_id = #{modelId}")
	@Results({@Result(column="model_id",property="modelId"),@Result(column="cpu_model",property="cpuModel"),
		@Result(column="cpu_core_num",property="cpuCoreNum"),@Result(column="ram_model",property="ramModel"),
		@Result(column="ram_volume",property="ramVolume"),@Result(column="disk_model",property="diskModel"),
		@Result(column="disk_volume",property="diskVolume"),@Result(column="ethernet_num",property="ethernetNum")})
	CpeModel getCpeExtListByModelId(Long modelId);

	@Insert("insert into res_base_cpe_ext(model_id,cpu_model,cpu_core_num,ram_model,ram_volume,disk_model,disk_volume,ethernet_num, update_date)"
			+ " values(#{modelId}, #{cpuModel}, #{cpuCoreNum}, #{ramModel}, #{ramVolume}, #{diskModel}, #{diskVolume}, #{ethernetNum},#{updateDate})")
	void insertCpeExt(CpeModel cpeModel);

	@Update("update res_base_cpe_ext set cpu_model=#{cpuModel},cpu_core_num=#{cpuCoreNum},ram_model=#{ramModel},ram_volume=#{ramVolume},"
			+ " disk_model=#{diskModel},disk_volume=#{diskVolume},ethernet_num=#{ethernetNum}, update_date=#{updateDate} where model_id = #{modelId}" )
	void updateCpeExt(CpeModel cpeModel);

	@Select("select a.eqpt_type as eqptType,c.brand_name brandName ,a.model_name modelName,a.eqpt_spec eqptSpec,b.cpu_model cpuModel,b.cpu_core_num cpuCoreNum, "
			+ " b.ram_model ramModel,b.ram_volume ramVolume,b.disk_model diskModel,b.disk_volume diskVolume,b.ethernet_num ethernetNum"
			+ " from res_base_model a,res_base_cpe_ext b,res_base_brand c"
			+ " where a.model_id=b.model_id and a.eqpt_type=#{eqptType} and a.brand_id=ifnull(#{brandId},a.brand_id) and a.state ='1'"
			+ " and a.brand_id = c.brand_id")
	List<Map<String, Object>> getCpeModelByTypeAndBrandId(@Param("eqptType")String eqptType, @Param("brandId")Long brandId);

}
